
import 'package:dio/dio.dart';
import 'package:sptapp/config/const.dart';

import '../../basic/base_info.dart';
import '../../utils/string_tool.dart';


// TODO 做成独立的Package，供多个app使用
/// 签名拦截器
class SignInterceptor extends InterceptorsWrapper {

  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    // TODO: implement onRequest

    super.onRequest(options, handler);
    String? token = LocalBaseInfo.getToken();
    if(token!=null&&token.isNotEmpty){
      options.headers["X-Access-Token"] = token;
      options.headers["token"] = token;
      options.headers["Authorization"] = "Bearer $token";
    }
    options.headers["version"] = baseVersion;
    print("****request****${DateTime.now()}");
    print("****url****"+options.baseUrl+options.path);
    if(options.headers!=null){
      StringTool.long_p("****log_headers****"+options.headers.toString());
    }
    if(options.data!=null){
      StringTool.long_p("****log_body****"+options.data.toString());
    }
    if(options.queryParameters!=null){
      StringTool.long_p("****log_queryParameters****"+options.queryParameters.toString());
    }


  }
}
